package com.zyj.persion.service.impl;

import java.util.List;

import com.zyj.assets.domain.AssetsInfo;
import com.zyj.common.core.text.Convert;
import com.zyj.common.utils.DateUtils;
import com.zyj.common.utils.StringUtils;
import com.zyj.persion.domain.AssetsPresion;
import com.zyj.persion.mapper.AssetsPresionMapper;
import com.zyj.persion.service.IAssetsPresionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import org.springframework.transaction.annotation.Transactional;

/**
 * 人员资产Service业务层处理
 * 
 * @author zhuyujie
 * @date 2022-05-09
 */
@Service
public class AssetsPresionServiceImpl implements IAssetsPresionService
{
    @Autowired
    private AssetsPresionMapper assetsPresionMapper;

    /**
     * 查询人员资产
     * 
     * @param assetsPersionId 人员资产主键
     * @return 人员资产
     */
    @Override
    public List<AssetsInfo> selectAssetsPresionByAssetsPersionId(Long assetsPersionId)
    {
        return assetsPresionMapper.selectAssetsPresionByAssetsPersionId(assetsPersionId);
    }

    /**
     * 查询人员资产列表
     * 
     * @param assetsPresion 人员资产
     * @return 人员资产
     */
    @Override
    public List<AssetsPresion> selectAssetsPresionList(AssetsPresion assetsPresion)
    {
        return assetsPresionMapper.selectAssetsPresionList(assetsPresion);
    }

    /**
     * 新增人员资产
     * 
     * @param assetsPresion 人员资产
     * @return 结果
     */
    @Transactional
    @Override
    public int insertAssetsPresion(AssetsPresion assetsPresion)
    {
        assetsPresion.setCreateTime(DateUtils.getNowDate());
        int rows = assetsPresionMapper.insertAssetsPresion(assetsPresion);
        insertAssetsInfo(assetsPresion);
        return rows;
    }

    /**
     * 修改人员资产
     * 
     * @param assetsPresion 人员资产
     * @return 结果
     */
    @Transactional
    @Override
    public int updateAssetsPresion(AssetsPresion assetsPresion)
    {
        assetsPresionMapper.deleteAssetsInfoById(assetsPresion.getAssetsPersionId());
        insertAssetsInfo(assetsPresion);
        return assetsPresionMapper.updateAssetsPresion(assetsPresion);
    }

    /**
     * 批量删除人员资产
     * 
     * @param assetsPersionIds 需要删除的人员资产主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteAssetsPresionByAssetsPersionIds(String assetsPersionIds)
    {
        assetsPresionMapper.deleteAssetsInfoByIds(Convert.toStrArray(assetsPersionIds));
        return assetsPresionMapper.deleteAssetsPresionByAssetsPersionIds(Convert.toStrArray(assetsPersionIds));
    }

    /**
     * 删除人员资产信息
     * 
     * @param assetsPersionId 人员资产主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteAssetsPresionByAssetsPersionId(Long assetsPersionId)
    {
        assetsPresionMapper.deleteAssetsInfoById(assetsPersionId);
        return assetsPresionMapper.deleteAssetsPresionByAssetsPersionId(assetsPersionId);
    }

    /**
     * 新增资产信息
     * 
     * @param assetsPresion 人员资产对象
     */
    public void insertAssetsInfo(AssetsPresion assetsPresion)
    {
//        List<AssetsInfo> assetsInfoList = assetsPresion.getAssetsInfoList();
//        Long assetsPersionId = assetsPresion.getAssetsPersionId();
//        if (StringUtils.isNotNull(assetsInfoList))
//        {
//            List<AssetsInfo> list = new ArrayList<AssetsInfo>();
//            for (AssetsInfo assetsInfo : assetsInfoList)
//            {
//                assetsInfo.setId(assetsPersionId+"");
//                list.add(assetsInfo);
//            }
//            if (list.size() > 0)
//            {
//                assetsPresionMapper.batchAssetsInfo(list);
//            }
//        }
    }

    public List<AssetsInfo> selectAllAssets(AssetsInfo assetsInfo){
        return assetsPresionMapper.selectAllAssets(assetsInfo);
    }
}
